home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / uldial.zip / ULROOT.PAS < prev   
Pascal/Delphi Source File  |  1990-07-12  |  16KB  |  479 lines

  1. (***********************************************************************
  2.      General Ojbects as Enhancements to Turbo Power OOP Professional
  3.                   New Communications Technology, Inc.
  4.                              Version 1.0
  5.                           by John Poindexter
  6.                              June 1, 1990
  7. ************************************************************************)
  8. {$I ULDEFINE.INC}
  9.  
  10. {$IFNDEF roDEBUG}
  11. {$A-,B-,E+,F+,I+,N-,O+,R-,S-,V-}
  12. {$ELSE}
  13. {$A-,B-,E+,F+,I+,N-,O+,R+,S+,V-}
  14. {$ENDIF}
  15.  
  16. Unit ULRoot;
  17.  
  18. Interface
  19.  
  20. Uses OpRoot, OpCrt, OpColor, OpMouse, OpInline, OpString, OpCmd,
  21.      OpFrame, OpWindow, OpPick, OpField, OpEntry, OpKey;
  22.  
  23. const
  24.   ucULRoot  = 200;
  25.   ucULDial  = 201;
  26.   ucULData  = 202;
  27.   ucULDbase = 203;
  28.  
  29.   epNoError = etNoError * 10000;
  30.  
  31. { Error Numbers and Messages }
  32. { Format of this area between ErrorStrs and EndErrorStrs is critical. }
  33. { Must alternate error code numbers and strings. This area may be }
  34. { searched to find error messages. }
  35. const ErrorStrs             : byte = 1;  { beginning of string storage }
  36.       ecTooManyKeys         = 3001;
  37. const emTooManyKeys         : string[13] = 'Too many keys';
  38.       ecNoLists             = 3002;
  39. const emNoLists             : string[24] = 'Desc or Key Lists failed';
  40.       ecKeyTooLong          = 3003;
  41. const emKeyTooLong          : string[15] = 'Key is too long';
  42.       ecInvalidDbaseNum     = 3004;
  43. const emInvalidDbaseNum     : string[31] = 'Requested Dbase not initialized';
  44.       ecInvalidIndex        = 3005;
  45. const emInvalidIndex        : string[33] = 'Invalid index for data descriptor';
  46.       ecNoVRecBuf           = 3006;
  47. const emNoVRecBuf           : string[34] = 'VRec buffer too small or no memory';
  48.       ecRebuildReq          = 3007;
  49. const emRebuildReq          : string[38] = 'Index is damaged. Select Ok to rebuild';
  50.       ecTooManyVar          = 3008;
  51. const emTooManyVar          : string[36] = 'May only use 1 variable length field';
  52.       ecDuplicateKeys       = 3009;
  53. const emDuplicateKeys       : string[32] = 'You have entered a duplicate key';
  54.       ecNoChoice            = 3010;
  55. const emNoChoice            : string[23] = 'DialogBox has no choice';
  56.       ecIgnoreChanges       = 3011;
  57. const emIgnoreChanges       : string[30] = 'You made changes. Record them?';
  58.       ecLockNoAccess        = 3012;
  59. const emLockNoAccess        : string[22] = 'A lock prevents access';
  60.       ecFileInUse           = 3013;
  61. const emFileInUse           : string[28] = 'The file is presently in use';
  62.       ecNoReadRec           = 3014;
  63. const emNoReadRec           : string[34] = 'Record could not be read from disk';
  64.       ecRecChanged          = 3015;
  65. const emRecChanged          : string[23] = 'Record has been changed';
  66.       ecRecDeleted          = 3016;
  67. const emRecDeleted          : string[23] = 'Record has been deleted';
  68.       ecNoWordField         = 3017;
  69. const emNoWordField         : string[43] = 'Field preceding variable field must be word';
  70.       ecCreateIFB           = 3018;
  71. const emCreateIFB           : string[41] = 'Data file does not exist. Create new one?';
  72.       ecDupFileName         = 3019;
  73. const emDupFileName         : string[45] = 'Data file exists and will overwrite. Proceed?';
  74.       ecInvalidWSNr         = 3020;
  75. const emInvalidWSNr         : string[26] = 'Invalid WorkStation number';
  76.       ecInitSemaFail        = 3021;
  77. const emInitSemaFail        : string[32] = 'Initialization Semaphores failed';
  78.       ecNoRecords           = 3022;
  79. const emNoRecords           : string[30] = 'There are no records. Add one?';
  80.       ecConfirmDel          = 3023;
  81. const emConfirmDel          : string[30] = 'Prepared to delete this record';
  82.       ecConfirmTagDel       = 3024;
  83. const emConfirmTagDel       : string[37] = 'Prepared to delete all tagged records';
  84.       ecNoMatching          = 3025;
  85. const emNoMatching          : string[24] = 'No matching record found';
  86.       ecOkToFilter          = 3026;
  87. const emOkToFilter          : string[28] = 'Ok to filter with this data?';
  88.       ecQuitBrowse          = 3027;
  89. const emQuitBrowse          : string[14] = 'Quit Browsing?';
  90.       ecTagsNotFirst        = 3028;
  91. const emTagsNotFirst        : string[29] = 'Tag field must be first added';
  92.       ecTagTooShort         = 3029;
  93. const emTagTooShort         : string[47] = 'Tag field too short for number of work stations';
  94. const emISAM                : string[4]  = 'ISAM';
  95. const emStatusHandlerFail   : string[21] = 'Status Handler failed';
  96. const emPossibleRecovery    : string[35] = 'Recovery may be possible with Retry';
  97.  
  98. const mmAnyKeytoContinue    : string[27] = ' Press any key to continue ';
  99.  
  100. const EndErrorStrs          : byte = 0;
  101.  
  102. const
  103. { Help Indices }
  104.   hiChangeDisplay       = 1;
  105.   hiSearch              = 2;
  106.   hiDialogBox           = 3;
  107.  
  108.   ULColorSet : ColorSet = (
  109.     TextColor       : BlackonLtGray; TextMono       : $07;
  110.     CtrlColor       : WhiteonBlue;   CtrlMono       : $07;
  111.     FrameColor      : YellowonBlue;  FrameMono      : $0F;
  112.     HeaderColor     : YellowonBlue;  HeaderMono     : $0F;
  113.     ShadowColor     : LtGrayonBlack;  ShadowMono     : $07;
  114.     HighlightColor  : WhiteonRed;    HighlightMono  : $70;
  115.     PromptColor     : BlackonLtGray; PromptMono     : $07;
  116.     SelPromptColor  : BlackonLtGray; SelPromptMono  : $07;
  117.     ProPromptColor  : BlueonLtGray;  ProPromptMono  : $07;
  118.     FieldColor      : BlackonLtGray; FieldMono      : $0F;
  119.     SelFieldColor   : WhiteonBlue;   SelFieldMono   : $70;
  120.     ProFieldColor   : BlueonLtGray;  ProFieldMono   : $07;
  121.     ScrollBarColor  : YellowonBlue;  ScrollBarMono  : $07;
  122.     SliderColor     : YellowonBlue;  SliderMono     : $07;
  123.     HotSpotColor    : WhiteonCyan;   HotSpotMono    : $07;
  124.     BlockColor      : WhiteonBlue;   BlockMono      : $0F;
  125.     MarkerColor     : YellowonLtGray;MarkerMono     : $70;
  126.     DelimColor      : BlackonLtGray; DelimMono      : $0F;
  127.     SelDelimColor   : WhiteonBlue;   SelDelimMono   : $70;
  128.     ProDelimColor   : BlueonLtGray;  ProDelimMono   : $07;
  129.     SelItemColor    : WhiteonRed;    SelItemMono    : $70;
  130.     ProItemColor    : BrownonLtGray; ProItemMono    : $01;
  131.     HighItemColor   : WhiteonRed;    HighItemMono   : $0F;
  132.     AltItemColor    : BlueonLtGray;  AltItemMono    : $0F;
  133.     AltSelItemColor : LtBlueonLtGray;AltSelItemMono : $70;
  134.     FlexAHelpColor  : WhiteonLtGray; FlexAHelpMono  : $0F;
  135.     FlexBHelpColor  : YellowOnRed;   FlexBHelpMono  : $01;
  136.     FlexCHelpColor  : GreenonBlack;  FlexCHelpMono  : $70;
  137.     UnselXrefColor  : YellowonBlack; UnselXrefMono  : $09;
  138.     SelXrefColor    : WhiteonRed;    SelXrefMono    : $70;
  139.     MouseColor      : WhiteonRed;    MouseMono      : $70
  140.   );
  141.  
  142.   WindowStep : byte = 1;
  143.  
  144. var
  145.   ULRootColorSet : ColorSet;
  146.   HeadFootAttr : byte;
  147.  
  148. type
  149.  
  150. (************************************************************************
  151.   The IndexDblList object desends from DoubleList and adds a GET method
  152.   to return a pointer to the nth node.
  153. ************************************************************************)
  154.  
  155.   IndexDblListPtr = ^IndexDblList;
  156.   IndexDblList = object(DoubleList)
  157.     function Get(Index: word): DoubleNodePtr; virtual;
  158.   end;
  159.  
  160. (************************************************************************
  161.   The MStringArray descends from StringArray and adds a data field and
  162.   methods for determining and getting the max string length in the array.
  163.   For this to function you must use AddMString vice AddString.
  164. ************************************************************************)
  165.  
  166.   MStringArrayPtr = ^MStringArray;
  167.   MStringArray = object(StringArray)
  168.     msMaxLen : byte;
  169.     constructor Init(Num, Amount: word);
  170.     function AddMString(St : string): word;
  171.     function GetMaxLen: byte;
  172.   end;
  173.  
  174. (************************************************************************
  175.   Global Routines
  176. ************************************************************************)
  177.  
  178. {$IFDEF UseAdjustableWindows}
  179. procedure MoveCmdWindow(WP: CommandWindowPtr);
  180. procedure ResizeCmdWindow(WP: CommandWindowPtr);
  181. procedure ToggleZoom(WP: CommandWindowPtr);
  182. {$ENDIF}
  183. function IncPtr(P: pointer; W: word): pointer;
  184. function GetGoodCoord(first, wide, maxwide: byte): byte;
  185. function Extend(S : String; Len : Byte) : String;
  186. procedure SimpStatus(UnitCode:byte; var Code: word; Msg:string);
  187. function Center1(OuterWidth, InnerWidth: word): word;
  188. function Coord2(FirstCoord, InnerWidth: word): word;
  189. procedure InitCrt;
  190. procedure RestoreCrt;
  191. procedure Abort;
  192. procedure WriteFooter(Prompt : String);
  193. function SizeOfObject(TypOf: pointer): word;
  194. procedure PromoteAncestor(Ancestor, TypOf: pointer);
  195. procedure NullConversion(EFP: EntryFieldPtr; PostEdit: boolean);
  196.  
  197. (***********************************************************************)
  198. Implementation
  199. (***********************************************************************)
  200.  
  201. {$IFDEF UseAdjustableWindows}
  202.  
  203. procedure MoveCmdWindow(WP: CommandWindowPtr);
  204.   {-Move any window interactively}
  205. var
  206.   Finished : Boolean;
  207. begin
  208.   if WP^.IsZoomed then
  209.     Exit;
  210.   WriteFooter(' Use cursor keys to move, {Enter} to accept');
  211.   Finished := False;
  212.   with WP^ do
  213.     repeat
  214.       case ReadKeyWord of
  215.         $4700 : MoveWindow(-WindowStep, -WindowStep); {Home}
  216.         $4800 : MoveWindow(0, -WindowStep);           {Up arrow}
  217.         $4900 : MoveWindow(WindowStep, -WindowStep);  {PgUp}
  218.         $4B00 : MoveWindow(-WindowStep, 0);           {Left Arrow}
  219.         $4D00 : MoveWindow(WindowStep, 0);            {Right Arrow}
  220.         $4F00 : MoveWindow(-WindowStep, WindowStep);  {End}
  221.         $5000 : MoveWindow(0, WindowStep);            {Down arrow}
  222.         $5100 : MoveWindow(WindowStep, WindowStep);   {PgDn}
  223.         $1C0D : Finished := True;                     {Enter}
  224.       end;
  225.  
  226.       if ClassifyError(GetLastError) = etFatal then
  227.         Abort;
  228.     until Finished;
  229.  
  230.   WriteFooter('');
  231. end;
  232.  
  233. procedure ResizeCmdWindow(WP: CommandWindowPtr);
  234.   {-Resize any window interactively}
  235. var
  236.   Finished : Boolean;
  237. begin
  238.   if WP^.IsZoomed then
  239.     Exit;
  240.   WriteFooter(' Use cursor keys to resize, {Enter} to accept');
  241.   Finished := False;
  242.   with WP^ do
  243.     repeat
  244.       case ReadKeyWord of
  245.         $4700 : ResizeWindow(-WindowStep, -WindowStep); {Home}
  246.         $4800 : ResizeWindow(0, -WindowStep);           {Up}
  247.         $4900 : ResizeWindow(WindowStep, -WindowStep);  {PgUp}
  248.         $4B00 : ResizeWindow(-WindowStep, 0);           {Left}
  249.         $4D00 : ResizeWindow(WindowStep, 0);            {Right}
  250.         $4F00 : ResizeWindow(-WindowStep, WindowStep);  {End}
  251.         $5000 : ResizeWindow(0, WindowStep);            {Down}
  252.         $5100 : ResizeWindow(WindowStep, WindowStep);   {PgDn}
  253.         $1C0D : Finished := True;                       {Enter}
  254.       end;
  255.  
  256.       if ClassifyError(GetLastError) = etFatal then
  257.         Abort;
  258.     until Finished;
  259.  
  260.   WriteFooter('');
  261. end;
  262.  
  263. procedure ToggleZoom(WP: CommandWindowPtr);
  264.   {-Toggle zoom status of any window}
  265. begin
  266.   with WP^ do begin
  267.     if IsZoomed then
  268.       Unzoom
  269.     else
  270.       Zoom;
  271.  
  272.     if ClassifyError(GetLastError) = etFatal then
  273.       Abort;
  274.   end;
  275. end;
  276. {$ENDIF}
  277.  
  278. function IncPtr(P: pointer; W: word): pointer;
  279. begin
  280.   IncPtr := AddWordToPtr(Normalized(P), W)
  281. end;
  282.  
  283. function GetGoodCoord(first, wide, maxwide: byte): byte;
  284.   {adjusts first coordinate if necessary so that a display will fit on screen}
  285. var
  286.   i,j : integer;
  287. begin
  288.   i := first - 1 + wide;
  289.   if i > Succ(maxwide) then
  290.   begin
  291.     i := i - Succ(maxwide);
  292.     j := first - i;
  293.     if j < 2 then GetGoodCoord := 2
  294.     else GetGoodCoord := j;
  295.   end
  296.   else GetGoodCoord := first;
  297. end;
  298.  
  299. function Extend(S : String; Len : Byte) : String;
  300.   {-Pad or truncate string to specified length}
  301. var
  302.   SLen : Byte absolute S;
  303. begin
  304.   if SLen >= Len then begin
  305.     SLen := Len;
  306.     Extend := S;
  307.   end
  308.   else
  309.     Extend := Pad(S, Len);
  310. end;
  311.  
  312. const
  313.   SavedState : boolean = false;
  314.  
  315. var
  316.   (* Various Crt parameters that are saved for later restoration *)
  317.   SaveAttr : byte;
  318.   SaveChar : char;
  319.   SaveXY, SaveScanLines : word;
  320.   SaveMode : byte;
  321.   SaveDir : string[64];
  322.   SaveBreak, SaveEOF : boolean;
  323.   {$IFDEF UseMouse}
  324.   MouseState : boolean;
  325.   {$ENDIF}
  326.  
  327. (* Initializes Crt and Save parameters *)
  328. procedure InitCrt;
  329. begin
  330.   GetDir(0,SaveDir);
  331.   GetCursorState(SaveXY, SaveScanlines);
  332.   SaveBreak := CheckBreak;
  333.   SaveEOF := CheckEOF;
  334.   ReInitCrt;
  335.   SaveMode := LastMode;
  336.   SaveAttr := ReadAttrAtCursor;
  337.   SaveChar := ReadCharAtCursor;
  338.   SavedState := true;
  339.   {$IFDEF UseMouse}
  340.   if MouseInstalled then HideMousePrim(MouseState);
  341.   {$ENDIF}
  342. end;
  343.  
  344. (* Restores Global Parameters to their original *)
  345. procedure RestoreCrt;
  346. begin
  347.   {$IFDEF UseMouse}
  348.   if MouseInstalled then ShowMousePrim(MouseState);
  349.   {$ENDIF}
  350.   ChDir(SaveDir);
  351.   RestoreCursorState(SaveXY, SaveScanlines);
  352.   CheckBreak := SaveBreak;
  353.   CheckEOF := SaveEOF;
  354.   TextMode(SaveMode);
  355.   TextAttr := SaveAttr;
  356.   TextChar := SaveChar;
  357.   ClrScr;
  358. end;
  359.  
  360. (* Centering Functions *)
  361. function Center1(OuterWidth, InnerWidth: word): word;
  362. begin
  363.   Center1 := (OuterWidth - InnerWidth) div 2 + 1;
  364. end;
  365.  
  366. function Coord2(FirstCoord, InnerWidth: word): word;
  367. begin
  368.   Coord2 := FirstCoord + InnerWidth - 1;
  369. end;
  370.  
  371. (* Simple Status and Error Handler *)
  372. procedure SimpStatus(UnitCode:byte; var Code: word; Msg:string);
  373. begin
  374.   RingBell;
  375.   WriteLn(Msg, 'Unit: ',UnitCode,' Error: ',Code);
  376. end;
  377.  
  378. (* MStringArray Methods *)
  379. constructor MStringArray.Init(Num, Amount: word);
  380. begin
  381.   StringArray.Init(Num, Amount);
  382.   msMaxLen := 0;
  383. end;
  384.  
  385. function MStringArray.AddMString(St : string): word;
  386. var
  387.   Len : byte absolute St;
  388.   Index : word;
  389. begin
  390.   Index := AddString(St);
  391.   if Index <> 0 then msMaxLen := MaxWord(msMaxLen, Len);
  392.   AddMString := Index;
  393. end;
  394.  
  395. function MStringArray.GetMaxLen: byte;
  396. begin
  397.   GetMaxLen := msMaxLen;
  398. end;
  399.  
  400. (* IndexDblList Methods *)
  401. function IndexDblList.Get(Index: word): DoubleNodePtr;
  402. var i : word;
  403.     p : DoubleNodePtr;
  404. begin
  405.   if Index > Size then
  406.   begin
  407.     Get := nil;
  408.     Exit;
  409.   end;
  410.   p := Head;
  411.   for i := 2 to Index do p := Next(p);
  412.   Get := p;
  413. end;
  414.  
  415. (*********************)
  416.  
  417. procedure Abort;
  418.   {-Abort the program with an out-of-memory error message}
  419. begin
  420.   if SavedState then RestoreCrt
  421.   else
  422.   begin
  423.     NormalCursor;
  424.     ClrScr;
  425.   end;
  426.   WriteLn('Insufficient memory available to continue.');
  427.   Halt(1);
  428. end;
  429.  
  430. procedure WriteFooter(Prompt : String);
  431.   {-Write a footer on the menu line}
  432. {$IFDEF UseMouse}
  433. var
  434.   SaveMouse : Boolean;
  435. {$ENDIF}
  436. begin
  437.   {$IFDEF UseMouse}
  438.   HideMousePrim(SaveMouse);
  439.   {$ENDIF}
  440.  
  441.   FastWrite(Extend(Prompt, ScreenWidth), ScreenHeight, 1, HeadFootAttr);
  442.   GotoXYabs(Length(Prompt)+2, ScreenHeight);
  443.  
  444.   {$IFDEF UseMouse}
  445.   ShowMousePrim(SaveMouse);
  446.   {$ENDIF}
  447. end;
  448.  
  449. function SizeOfObject(TypOf: pointer): word;
  450.   { TypOf must have been returned by the TypeOf function which returns the
  451.     address of the VMT. The first word of the VMT is the size of the instance.}
  452. begin
  453.   SizeOfObject := word(TypOf^);
  454. end;
  455.  
  456. procedure PromoteAncestor(Ancestor, TypOf: pointer);
  457.   { This only works if the VMT link is the first two bytes of the ancestor
  458.     as in descendants of Root and TypOf has been returned by
  459.     TypeOf(Descendant). Otherwise it most probably will cause a crash! }
  460. var
  461.   VMTOfs : word;
  462. begin
  463.   VMTOfs := Word(PtrDiff(Ptr(DSeg,0),TypOf));
  464.   Move(VMTOfs, Ancestor^, 2);  {fixup VMT link}
  465. end;
  466.  
  467. procedure NullConversion(EFP: EntryFieldPtr; PostEdit: boolean);
  468.   { a dummy procedure that should never be called }
  469. begin
  470.   Abstract;
  471. end;
  472.  
  473. (*******************************)
  474. begin
  475.   ULRootColorSet := ULColorSet;
  476.   with ULRootColorSet do
  477.   HeadFootAttr := ColorMono(HighLightColor, HighLightMono);
  478. End.
  479.